"
I serialize an MCVersionInfo into a given stream.
If the version info has been serialized before I output a compacted version consiting of the id.

"
Class {
	#name : 'MCVersionInfoWriter',
	#superclass : 'MCWriter',
	#instVars : [
		'written'
	],
	#category : 'Monticello-Storing',
	#package : 'Monticello',
	#tag : 'Storing'
}

{ #category : 'testing' }
MCVersionInfoWriter >> isWritten: aVersionInfo [
	^ self written includes: aVersionInfo
]

{ #category : 'serialization' }
MCVersionInfoWriter >> writeVersionInfo: aVersionInfo [
	(self isWritten: aVersionInfo)
		ifTrue: [^ stream nextPutAll: '(id '; print: aVersionInfo id asString; nextPut: $) ].
	stream nextPut: $(.
	#(name message id date time author) do: [:sel | | toWrite |
		toWrite := (aVersionInfo perform: sel) ifNil: [''].
		sel = #date
			ifTrue: [ toWrite := toWrite yyyymmdd ].
		stream 
			nextPutAll: sel; space;
			print: (toWrite asString encodeWith: #utf8  ) asString; space ].
	stream nextPutAll: 'ancestors ('.
	aVersionInfo ancestors do: [:ea | self writeVersionInfo: ea].
	stream nextPutAll: ') stepChildren ('.
	aVersionInfo stepChildren do: [:ea | self writeVersionInfo: ea].
	stream nextPutAll: '))'.
	
	self wrote: aVersionInfo
]

{ #category : 'accessing' }
MCVersionInfoWriter >> written [
	^ written ifNil: [written := Set new]
]

{ #category : 'serialization' }
MCVersionInfoWriter >> wrote: aVersionInfo [
	self written add: aVersionInfo
]
